package com.tycmc.kafka;

import com.tycmc.common.util.Property;
import org.apache.kafka.clients.consumer.KafkaConsumer;


import java.util.Arrays;
import java.util.Properties;

public class CreateKafkaConsumer {

    public KafkaConsumer<String, byte[]> init(){
        //创建日志队列kafka生产者
        Properties proConsumer = new Properties();
        proConsumer.put("bootstrap.servers", Property.getProperty("consumer.bootstrap.servers"));
        proConsumer.put("group.id", Property.getProperty("consumer.group.id"));
        proConsumer.put("max.poll.records", Property.getProperty("consumer.max.poll.records"));
        proConsumer.put("enable.auto.commit", Property.getProperty("consumer.enable.auto.commit"));
        proConsumer.put("auto.offset.reset", Property.getProperty("consumer.auto.offset.reset"));
        proConsumer.put("auto.commit.interval.ms", Property.getProperty("consumer.auto.commit.interval.ms"));
        proConsumer.put("key.deserializer", Property.getProperty("consumer.key.deserializer"));
        proConsumer.put("value.deserializer", Property.getProperty("consumer.value.deserializer"));
        KafkaConsumer<String, byte[]> consumer = new KafkaConsumer<>(proConsumer);
        consumer.subscribe(Arrays.asList(Property.getProperty("consumer.topic").split(",")));
        return consumer;
    }

}
